Thực đơn
Chỉ định truy cập Ví dụ trong C++#include <iostream>using std::cout;using std::endl;struct B { // default access modifier inside struct is public void set_n(int v) { n = v; } void f() { cout << "B::f" << endl; } protected: int m, n; // B::m, B::n are protected private: int x;}; struct D: B { using B::m; // D::m is public int get_n() { return n; } // B::n is accessible here, but not outside// int get_x() { return x; } // ERROR, B::x is inaccessible here private: using B::f; // D::f is private}; int main() { D d;// d.x = 2; // ERROR, private// d.n = 2; // ERROR, protected d.m = 2; // protected B::m is accessible as D::m d.set_n(2); // calls B::set_n(int) cout << d.get_n() << endl; // output: 2// d.f(); // ERROR, B::f is inaccessible as D::f B& b = d; // b references d and "views" it as being type B// b.x = 3; // ERROR, private// b.n = 3; // ERROR, protected// b.m = 3; // ERROR, B::m is protected b.set_n(3); // calls B::set_n(int)// cout << b.get_n(); // ERROR, 'struct B' has no member named 'get_n' b.f(); // calls B::f() return 0;}
Thực đơn
Chỉ định truy cập Ví dụ trong C++Liên quan
Chỉ Chỉ số thông minh Chỉ mình tôi thăng cấp Chỉ số nhận thức tham nhũng Chỉ số tự do kinh tế Chỉ số chất lượng không khí Chỉ số khối cơ thể Chỉ có thể là yêu (phim Hàn Quốc) Chỉ số phát triển con người Chỉ số FTSE 100Tài liệu tham khảo
WikiPedia: Chỉ định truy cập https://books.google.com/books?id=XdHYaE-Il9gC